<style lang="less" scoped>
.ivu-shrinkable-menu {
    height: 100%;
    width: 100%;
}

</style>
<template>
    <Menu ref="sideMenu" :active-name="$route.name" :open-names="openNames" :theme="menuTheme" width="auto" @on-select="changeMenu" accordion>
        <template v-for="item in menuList">
            <template v-if="item.visible == 1">
                <MenuItem v-if="item.children.length<=1" :name="item.children[0].name" :key="item.path">
                    <Icon :type="item.icon" :size="iconSize"></Icon>
                    <span class="layout-text">{{ itemTitle(item) }}</span>
                </MenuItem>
                <Submenu v-if="item.children.length > 1" :name="item.name" :key="item.path">
                    <template slot="title">
                        <Icon :type="item.icon" :size="iconSize"></Icon>
                        <span class="layout-text">{{ itemTitle(item) }}</span>
                    </template>
                    <template v-for="child in item.children">
                        <template v-if="child.visible == 1">
                            <MenuItem :name="child.name" :key="child.name">
                                <Icon :type="child.icon" :size="iconSize"></Icon>
                                <span class="layout-text">{{ child.title }}</span>
                            </MenuItem>
                        </template>
                    </template>
                </Submenu>
            </template>
        </template>
    </Menu>
</template>
<script>
export default {
    name: 'sidebarMenu',
    props: {
        menuList: Array,
        iconSize: Number,
        menuTheme: {
            type: String,
            default: 'dark'
        },
        openNames: {
            type: Array
        }
    },
    methods: {
        changeMenu(active) {
            this.$emit('on-change', active);
        },
        itemTitle(item) {
            if (typeof item.title === 'object') {
                return this.$t(item.title.i18n);
            } else {
                return item.title;
            }
        }
    },
    updated() {
        this.$nextTick(() => {
            if (this.$refs.sideMenu) {
                this.$refs.sideMenu.updateOpened();
            }
        });
    }

};
</script>
